package epam.lab.spring.reader;

import epam.lab.spring.context.ApplicationContext;
import epam.lab.spring.parser.BeanDOMParser;
import epam.lab.spring.parser.BeanParser;
import epam.lab.spring.parser.ParserTypes;

/**
 * Standard XML Bean Definition Reader
 * @author Iurii Miedviediev
 * @version 1.0 Build 21.08.2014
 */
public class XmlBeanDefinitionReader implements BeanDefinitionReader {

    private BeanParser parser;
    private ApplicationContext context;

    public XmlBeanDefinitionReader(ApplicationContext context) {
        this.context = context;
        parser = new BeanDOMParser();
    }


    @Override
    public void loadBeanDefinitions(String fileName) {
        context.setBeanDefinitions(parser.parseBeanXml(fileName));
    }

    @Override
    public void setParserType(ParserTypes parserType) {
        switch(parserType) {
            case SAX:
            case STAX:
                throw new UnsupportedOperationException();
            case DOM:
                parser = new BeanDOMParser();
                break;
            default:
                break;
        }
    }
}
